﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ToolsLayer;
using Webcar.BLL;

namespace Webcar.UI
{
    public partial class UnCompleteTraffic : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.IsPostBack) return;
                //未结案安全事故
                string sql = @"select SEC_NO,driver_name,dept_name,record_NO,sec_date_str,sec_place,loss_money from v_sec_record where sec_dept in 
            (select dept_code from bs_man_dept where man_code='{0}') and dept_delflag='F'
             and (child_dept in (select child_dept from bs_man_childdept where userid='{0}')
             or child_dept is null or child_dept='') and IS_END='F' order by sec_date desc";
                sql = string.Format(sql, CurrentUser.LoginUserID);
                if (CurrentUser.IsSuperUser())
                {
                    sql = @"select SEC_NO,driver_name,dept_name,record_NO,sec_date_str,sec_place,loss_money from v_sec_record where dept_delflag='F'
                        and IS_END='F' order by sec_date desc";
                }
                DataSet ds = DB.ExecuteDataset(sql);
                this.Repeater2.DataSource = ds;
                this.Repeater2.DataBind();
                //最近安全事故
                string sql2 = @"select top 5 SEC_NO,driver_name,dept_name,record_NO,sec_date_str,sec_place,loss_money from v_sec_record where
            dept_delflag='F' and sec_dept in 
            (select dept_code from bs_man_dept where man_code='{0}')
             and (child_dept in (select child_dept from bs_man_childdept where userid='{0}')
             or child_dept is null or child_dept='') order by sec_date desc";
                sql2 = string.Format(sql2, CurrentUser.LoginUserID);
                if (CurrentUser.IsSuperUser())
                {
                    sql2 = @"select top 5 SEC_NO,driver_name,dept_name,record_NO,sec_date_str,sec_place,loss_money from v_sec_record where
                    dept_delflag='F' order by sec_date desc";
                }
                DataSet ds2 = DB.ExecuteDataset(sql2);
                this.Repeater1.DataSource = ds2;
                this.Repeater1.DataBind();
            }
            catch (Exception ex)
            {
                new CurrentUser().LogError(ex);
            }
        }

        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HyperLink link = (HyperLink)e.Item.FindControl("hyperlink1");
            DataRowView row = e.Item.DataItem as DataRowView;
            string xh = row["SEC_NO"].ToString();
            Label newlabel = (Label)e.Item.FindControl("newlabel");

            InfoChecker ic = new InfoChecker();
            newlabel.Visible = !ic.InfoIsRead(xh, InfoCheckType.Sec);
        }
    }
}